﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8" />
    <title>子流程</title>
    <link href="../../../Comm/Style/CommStyle.css" rel="stylesheet" type="text/css" />
    <link href="../../../../DataUser/Style/ccbpm.css" rel="stylesheet" type="text/css" />
    <link href="../../../Scripts/easyUI/themes/default/easyui.css" rel="stylesheet" type="text/css" />
    <link href="../../../Scripts/easyUI/themes/icon.css" rel="stylesheet" type="text/css" />
    <script src="../../../Scripts/jquery-1.7.2.min.js" type="text/javascript"></script>
    <script src="../../../Scripts/easyUI/jquery.easyui.min.js" type="text/javascript"></script>
    <script src="../../../Scripts/QueryString.js" type="text/javascript"></script>
    <script type="text/javascript" src="../../../Scripts/config.js"></script>
    <script type="text/javascript" src="../../../Comm/Gener.js"></script>
    <script src="../../../Scripts/EasyUIUtility.js" type="text/javascript"></script>
    <base target="_self" />
    <script type="text/javascript">

        //页面启动函数.
        $(function () {
            $("#Msg").html("<img src=../../../Img/loading.gif />&nbsp;正在加载,请稍后......");

            //求出来已经设置的延续子流程.
            var nodeID = GetQueryString("FK_Node");
            var orgNo = GetQueryString("OrgNo");

            //查询出来数据.
            //    var sql = "SELECT A.No AS SortNo, A.Name as SORTNAME, b.No AS NO, b.Name AS FLOWNAME ";
            //    sql += " FROM WF_FlowSort a, WF_Flow b WHERE (A.OrgNo='" + orgNo + "' OR A.ParentNo='" + orgNo + "') AND A.No=B.FK_FlowSort ";
            //    sql += " ORDER BY A.Idx, b.Idx ";

            var dt = new Entities("BP.WF.Flows");
            dt.RetrieveAll("FlowSort");

            var Autos = new Entities("BP.WF.Template.SubFlowAutos");
            Autos.Retrieve("FK_Node", nodeID, "SubFlowType", 1);


            var html = "";
            for (var i = 0; i < dt.length; i++) {

                var en = dt[i];

                //console.log(en);

                html += "<tr>";

                html += "<td>" + en.FK_FlowSortText + "</td>";
                html += "<td>" + en.No + "</td>";
                html += "<td>" + en.Name + "</td>";

                var isHave = false;
                for (var myidx = 0; myidx < Autos.length; myidx++) {

                    var Auto = Autos[myidx];
                    if (Auto.FK_Flow == en.No) {
                        isHave = true;

                        if (Auto.FlowName != en.Name) {

                            var AutoEn = new Entity("BP.WF.Template.SubFlowAuto", Auto);
                            AutoEn.FlowName = en.Name;
                            AutoEn.Update();
                            //Auto.Update();
                        }
                        break;
                    }
                }

                if (isHave == false)
                    html += "<td><a href=\"javascript:CheckIt('" + en.No + "','" + en.Name + "');\" >选择</a></td>";
                else
                    html += "<td><font color=red>已存在</font></td>";

                html += "</tr>";
            }

            $("#Table1 tr:last").after(html);

        });


        function CheckIt(flowNo, name) {

            if (window.confirm('您确定要增加吗？') == false)
                return;

            var nodeID = GetQueryString("FK_Node");

            var ens = new Entities("BP.WF.Template.SubFlowAutos");
            ens.Retrieve("FK_Node", nodeID, "SubFlowNo", flowNo, "SubFlowType", 1);

            if (ens.length == 1) {
                alert("该流程已经存在");
                return;
            }

			var myNode = new Entity("BP.WF.Node", nodeID);
            var en = new Entity("BP.WF.Template.SubFlowAuto");

            en.SubFlowNo = flowNo;
            en.FK_Node = nodeID;
            en.SubFlowName = name;
            en.SubFlowType = 1;
            en.FK_Flow = myNode.FK_Flow;

            var myen = en.Insert();

            window.location.href = '../../../Comm/RefFunc/EnOnly.htm?EnName=BP.WF.Template.SubFlowAuto&PKVal=' + myen.MyPK;

            //alert('当前流程已经加入了延续流程中.');
        }
         
    </script>
</head>
<body>
    <table id="Table1" style="width: 100%">
        <caption>
            请选择一个子流程</caption>
        <tr>
            <th>
                流程类别
            </th>
            <th>
                流程编号
            </th>
            <th>
                名称
            </th>
            <th>
                操作
            </th>
        </tr>
    </table>
</body>
</html>
